package cn.edu.zut.hkxy.service.impl;

import cn.edu.zut.hkxy.mapper.TotalMapper;
import cn.edu.zut.hkxy.pojo.Article;
import cn.edu.zut.hkxy.pojo.ArticleCount;
import cn.edu.zut.hkxy.pojo.TableCount;
import cn.edu.zut.hkxy.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class TotalServiceImpl implements TotalService {
    @Autowired
    TotalMapper mapper;

    @Override
    public ArticleCount getCount() {
        List<TableCount> list=mapper.getAllCount();
        HashMap<String,Integer> map=new HashMap<>();
        for(TableCount tableCount:list){
            map.put(tableCount.getTable_name(),tableCount.getTable_rows());
        }
        ArticleCount articleCount=new ArticleCount();
        articleCount.setNews(map.get("news"));
        articleCount.setNotice(map.get("notice"));
        articleCount.setEduinfo(map.get("eduinfo"));
        articleCount.setStuinfo(map.get("stuinfo"));
        articleCount.setAdmissions(map.get("admissions"));
        articleCount.setJobs(map.get("jobs"));
        articleCount.setCommunication(map.get("communication"));
        articleCount.setScience(map.get("science"));
        articleCount.setCpc(map.get("cpc"));
        System.out.println(articleCount);
        return articleCount;
    }
}
